/**
 * 
 */
package fb.chatter.utils;

import java.util.ArrayList;
import java.util.List;

import fb.chatter.model.User;
import fb.chatter.model.Users;

/**
 * @author hoannguyen
 * 
 */
public final class FriendsUtils {

	/**
	 * To search the corresponding friends in the given friends parameter with
	 * the given friendName string.
	 * 
	 * @param friends
	 * @param friendName
	 * @return
	 */
	public static Users searchByFriendName(Users friends, String friendName) {
		Users result = new Users();
		List<User> friendList = new ArrayList<User>();

		for (User f : friends.getData()) {

			String s1 = StringUtils.removeToneOfVietnameseString(f.getName().toLowerCase());
			String s2 = StringUtils.removeToneOfVietnameseString(friendName.toLowerCase());
			if (s1.contains(s2)) {
				friendList.add(f);
			}
		}

		result.setData(friendList);
		return result;
	}
	
	/**
	 * To search the Friend in the @friends with the given friend ID 
	 * 
	 * @param friends
	 * @param id
	 * @return
	 */
	public static User searchByFriendId(Users friends, String id){
		
		for (User f : friends.getData()) {
			if(f.getId().equals(id)){
				return f;
			}
		}
		
		return null;
	}
}
